const OperationLog = require("../db/OperationLog");
const moment = require('moment');
const now = () => {
    return moment().format('YYYY-MM-DD HH:mm:ss')
}
const logger = require("../common/logger");
const Registrations = require("../db/RegistrationinforMation");
module.exports = {
    ////保存日志
    saveLog(obj) {
        OperationLog.create(obj, function (err, data) {
            if (!err) {
                logger.info("日志保存成功!")
            }
        })
    },
    //保存日志
    saveLogs(user, ip, text) {
        let pare = {
            id: user._id,
            name: user.name,
            roles: user.role,
            ip: ip,
            time: now(),
            Operationcontent: text
        };
        OperationLog.create(pare, function (err, data) {
            if (!err) {
                logger.info("日志保存成功!")
            }
        })
    },
    //挂号信息保存
    registration(obj) {
        let pare = {
            orderid: obj.orderid,
            receptiontime: obj.receptiontime,//接诊时间
            receptionstate: obj.receptionstate || 2,// 1  待分诊   2：待接诊   3：接诊中   4：已完成
            receptiontype: obj.receptiontype,//接诊类型   0:初诊   1:复诊
            department: obj.department,//科室
            doctor: obj.doctor,//医生
            registerpeople: obj.registerpeople,//登记人员
            registrationlv: obj.registrationlv,//挂号等级
            registrationmoney: obj.registrationmoney,//挂号费用
            paystate: obj.paystate,//支付状态
            payer: obj.payer,//付款人
        };
        Registrations.create(pare).then(data => {
            logger.info("挂号信息保存成功")
        }).catch(err => {
            console.log(err)
            logger.error("挂号信息保存失败")
        })
    }
}